﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Appointment Status Repository
    /// </summary>
    public class AppointmentStatusRepository : IAppointmentStatusRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Appointment Status Details by Title
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<AppointmentStatus> FindAppointmentStatusByName(string strQuery)
        {
            return _db.AppointmentStatus.Where(d => d.AppointmentStatusName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Appointment Status
        /// </summary>
        /// <returns></returns>
        public IQueryable<AppointmentStatus> FindAllAppointmentStatus()
        {
            return _db.AppointmentStatus;
        }

        /// <summary>
        /// Get Appointment Status by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AppointmentStatus GetAppointmentStatusById(int id)
        {
            return _db.AppointmentStatus.SingleOrDefault(d => d.AppointmentStatusId == id);
        }

        /// <summary>
        /// Add Appointment Status in the Database
        /// </summary>
        /// <param name="appointmentStatus"></param>
        public void Add(AppointmentStatus appointmentStatus)
        {
            _db.AppointmentStatus.AddObject(appointmentStatus);
        }

        /// <summary>
        /// Delete Appointment Status from Database
        /// </summary>
        /// <param name="appointmentStatus"></param>
        public void Delete(AppointmentStatus appointmentStatus)
        {
            _db.AppointmentStatus.DeleteObject(appointmentStatus);
        }

        /// <summary>
        /// Save Appointment Status in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}